define(['helper/tools'],function(tools){
	var _this = null;
	var init = function(){
		_this = this;
		// _this.view.init();
	};
	var dataTrans = {
		getWholeWord : function(){
			tools.ajax('user/notebook_list',{},
				function(res){
					tools.__UTILS.newWords = res;
				}
			)
		// tools.__UTILS.newWords = {"notebook_list": {"shawn":"肖恩","constrictor":"haah"}};
		// tools.__UTILS.newWords = {"notebook_list": {"shawn": "肖恩","constrictor": "大蟒蛇","publishing": "出版","trove": "宝库","attend": "参加","revolutionized":"彻底改变了","suggested": "建议","seemingly":"看似","narrator":"旁白","draft":"草案","frighten":"吓唬","arizona": "亚利桑那州","self-publishing": "自出版","hire":"雇用","primeval":"原始","near-brilliant": "近辉煌","twenty-two": "二十二","reenvision":"再想象","get":"得到","follow":"遵循","missing":"失踪","digestion":"消化","prey":"猎物","great":"太好了","constrictors": "大蟒蛇","hemingway": "海明威","minefield":"雷区","incredible":"简直不可思议","storygrid":"storygrid","magnificent":"宏伟的","energy":"能量","breakdown": "击穿"}};
		},
		getPredictWord : function(){
			tools.ajax('user/notebook_list_by_time',{},
				function(res){
					tools.__UTILS.newWords = res;
				}
			)
		}
	};
	var view = {
		newWordsPartShowHide: function(){
    		$('[data-new_words_part="'+tools.__UTILS.userActionRecord.newWordsCurrentPart+'"]').show().siblings().hide();
    	},
			
		page: function() {
			var new_words = tools.__UTILS.newWords.notebook_list,
    			count=0,part = 0;
			$(".word_list").html("");
    		$.each(new_words,function(i){
    			count++;
    			var cn_trans = new_words[i];
    			if(count % 8 == 1 ){
    				part++;
    				$(".word_list").append("<div class='new_words_part' data-new_words_part="+part+"></div>");
    				$("[data-new_words_part="+part+"]").append("<div class='word_item'><span class='vocabulary_new_word'>"+i+"</span><span class='vocabulary_cn_trans'>"+cn_trans+"</span></div>");
    			}
    			else{
    				$("[data-new_words_part="+part+"]").append("<div class='word_item'><span class='vocabulary_new_word'>"+i+"</span><span class='vocabulary_cn_trans'>"+cn_trans+"</span></div>");
    			}

    		});
    		//_this.regBtn.chanPage();
    		tools.__UTILS.userActionRecord.newWordsAllPart = $(".new_words_part").length;
    		tools.__UTILS.userActionRecord.newWordsCurrentPart = 1;
    		_this.view.newWordsPartShowHide();
    		$(".new_words_turn_page").show();
    		if(tools.__UTILS.userActionRecord.newWordsAllPart <= 1){
    			$(".new_words_turn_page").hide();
    		}
    		else{
    			$(".new_words_last_page").hide();
    		}

    	
		},
		contPos: function(){
            $(".vocabularyBook_main").css({
                height:$(document).height(),
                left:0.5*$(document).width()-325
            });
            $(window).resize(function(){
                $(".vocabularyBook_main").css({
                    height:$(document).height(),
                    left:0.5*$(document).width()-325
                });
            });
        },
		init: function(){
			if(tools.__UTILS.userActionRecord.newWordsType == "predict"){
				_this.dataTrans.getPredictWord();
			}
			else{
				_this.dataTrans.getWholeWord();
			}
			
			_this.view.page();
			tools.router("vocabularyBook");
		}
	};
	var regBtn = {
		
		init : function(){
			_this.view.contPos();
			$(".new_words_last_page").bind("click",function(){
					if(tools.__UTILS.userActionRecord.newWordsCurrentPart >=2){
						$(".new_words_next_page").show();
						tools.__UTILS.userActionRecord.newWordsCurrentPart--;
						_this.view.newWordsPartShowHide();
						if(tools.__UTILS.userActionRecord.newWordsCurrentPart == 1){
							$(".new_words_last_page").hide();
						}
					}
			});
			$(".new_words_next_page").bind("click",function(){
				if(tools.__UTILS.userActionRecord.newWordsCurrentPart < tools.__UTILS.userActionRecord.newWordsAllPart){
					$(".new_words_last_page").show();
					tools.__UTILS.userActionRecord.newWordsCurrentPart++;
					_this.view.newWordsPartShowHide();
					if(tools.__UTILS.userActionRecord.newWordsCurrentPart == tools.__UTILS.userActionRecord.newWordsAllPart){
						$(".new_words_next_page").hide();
					}
				}
			});
			$(".vocabularyBook_bookshelf_btn").bind("click",function(){
                tools.router("chooseBook");
            });
            $(".vocabularyBook_tab").bind("click",function(){
            	tools.__UTILS.userActionRecord.newWordsType = $(this).data("type");
            	if($(this).hasClass("vocabularyBook_whole_tab")){
            		$(".vocabularyBook_hr").animate({left:"120px"},1000);
            	}
            	else{
            		$(".vocabularyBook_hr").animate({left:"0"},1000)
            	}
            	$(".word_list").html("");
               _this.view.init();
            })

		}
	};
	return{
		init: init,
		regBtn: regBtn,
		dataTrans: dataTrans,
		view: view
	}
})